<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends   BaseController {
    public function index(){
        $this->display();
    }

    // 崔晓真 查看是否登录
    public function _initialize(){
        header("Content-type:text/html;charset=utf-8");
        if(ACTION_NAME!='index' && ACTION_NAME!='checkLogin'&& ACTION_NAME!='verify'){
            if(null==session('flag')|| session('flag')!='logok'){
                redirect('count');
            }
        }
    }
   
    // 崔晓真 检验二维码
    function check_verify($code, $id = ''){
        $verify = new \Think\Verify();
        return $verify->check($code, $id);
    }

    // 崔晓真 检验登录
    public function checkLogin(){  
        session('flag',null);
        $code=I('post.verify');
        if(!$this->check_verify($code))$this->error('验证码错误');
        $admin = M('admins');
        $map = array();
        $map['admin_name'] = I('post.username');
        $map['password'] = md5(I('post.password'));
       
        $res=$admin->where($map)->select();
        if($res==null){
            $this->error('用户名密码错误');
        }else {
            session("flag","logok");
            dump($_SESSION);
            redirect('count');
        }
    }

    public function verify(){
        ob_clean();
//        $config =    array(
//            'fontSize'    =>    30,    // 验证码字体大小
//            'length'      =>    3,     // 验证码位数
//            'useNoise'    =>    false, // 关闭验证码杂点
//            //'fontttf' => 'msyhbd.ttf',
//           
//
//            'useImgBg' => false,
//            //'useZh' => true,
//        );
//        $Verify = new \Think\Verify($config);
        $Verify = new \Think\Verify();
        $Verify->entry();
    }

    // 崔晓真 统计数据
    public function count(){
        $admin=M('admins');
        $admins=$admin->find();
        $this->admin=$admins;
        
        if(session('?flag')) {
            $games = M('games');
            $count1 = $games->count();
            $this->count1 = $count1;
            $trainings = M('trainings');
            $count2 = $trainings->count();
            $this->count2 = $count2;
            $photos = M('photos');
            $count3 = $photos->count();
            $this->count3 = $count3;
            $comments = M('comments');
            $count4 = $comments->count();
            $this->count4 = $count4;
            $users = M('user');
            $count5 = $users->count();
            $this->count5 = $count5;
            $teachers = M('teacher');
            $count6= $teachers->count();
            $this->count6 = $count6;
            $clubadmin = M('clubadmin');
            $count7= $clubadmin->count();
            $this->count7 = $count7;
            $activity = M('activity');
            $count8= $activity->count();
            $this->count8 = $count8;
            $club = M('club');
            $count9= $club->count();
            $this->count9 = $count9;
            $this->display();
            } 
        else {
            echo'没有登录';
        }
     }

    //崔晓真 注销
    public function signout(){
        if(session('?flag')){
            session('flag',null);
        }
        redirect('index');
    }
}